<template>
  <!-- /**
     *
     已录入 ---1
     待交件 ---2
     待放款 ---3
     已放款 ---4
     已回款 ---5
     已中止 ---6
     挂账   ---7
     */功能区
  -->
  <div>
    <div class="first">
      <h1 class="title_sub gn">功能区：</h1>
      <span v-if="showUpdateStatusBtn && orderStatus == 2">
        <el-button type="primary" size="small" @click="putUpdateStatus(3)"
          >标记已交件</el-button
        >
      </span>
      <!-- <span v-if="showUpdateStatusBtn && orderStatus == 2">
        <el-button type="primary" size="small" @click="putUpdateStatus(-2)"
          >标记交件失败</el-button
        >
      </span> -->
      <span v-if="showChargeBtn && orderStatus == 3">
        <el-button type="primary" size="small" @click="putUpdateStatus(4)"
          >标记已放款</el-button
        >
      </span>
      <!-- <span v-if="showChargeNoBtn && orderStatus == 3">
        <el-button type="primary" size="small" @click="putUpdateStatus(-3)"
          >标记为放款失败</el-button
        >
      </span> -->
      <span v-if="showChargeBtn && orderStatus == 5">
        <el-button type="primary" size="small" @click="putUpdateStatus(5)"
          >重置为已放款进行收款</el-button
        >
      </span>

      <span v-if="showChargeBtn && orderStatus == 4">
        <el-button type="primary" size="small" @click="putUpdateStatus(5)"
          >标记为已归档</el-button
        >
      </span>
      <el-button
        type="danger"
        size="small"
        v-if="markUpdate > 0 && showMarkUpdate"
        @click="markUpdateFun"
        >处理此订单更新</el-button
      >
    </div>
  </div>
</template>

<script>
import {
  putUpdateStatus,
  markUpdate,
  getProductUrl
} from "../../../src/assets/js/api";
import { checkPermiss } from "../../assets/js/utlis";
export default {
  name: "FunctionalAreas",
  created() {
    this.golbalPermissions = localStorage.getItem("permissions").split(",");
    this.orderNumber = sessionStorage.getItem("orderNumber");
    this.findProductUrl(this.orderNumber);
  },
  data() {
    return {
      orderStatus: "",
      orderNumber: "",
      markUpdate: "",
      markForm: {
        orderNumber: "",
        markUpdate: 0
      },
      golbalPermissions: [],
      ProductUrl: ""
    };
  },
  computed: {
    //订单更新按钮
    showMarkUpdate: function() {
      return checkPermiss("business:order:markUpdate", this.golbalPermissions);
    },
    // 待交件-标记(已交件,交件失败)按钮
    showUpdateStatusBtn: function() {
      return checkPermiss(
        "business:auction:updateStatusList",
        this.golbalPermissions
      );
    },
    //标记已归档按钮
    showReturnedStatusList: function() {
      return checkPermiss(
        "business:auction:updateStatus",
        this.golbalPermissions
      );
    },
    //标记已放款，
    showChargeBtn: function() {
      return checkPermiss(
        "business:auction:updateStatus",
        this.golbalPermissions
      );
    },
    //标记放款，放款失败
    showChargeNoBtn: function() {
      return checkPermiss(
        "business:auction:updateStatus",
        this.golbalPermissions
      );
    }
  },
  methods: {
    /**
     * 标记已交件 statusId ==3
     * 交件失败 statusId ==-2
     * 标记已放款 statusId ==4
     * 放款失败 statusId ==-3
     * 标记为已归档 statusId ==5
     * 标记为已归档 statusId ==7
     */
    putUpdateStatus(statusId) {
      //标记已交件
      putUpdateStatus({
        orderNumber: this.orderNumber,
        statusId: statusId
      }).then(res => {
        if (res.code == 200) {
          this.$message({
            message: res.message,
            type: "success"
          });
          this.$router.replace({ path: this.ProductUrl });
        } else {
          this.$message({
            message: res.message,
            type: "error"
          });
        }
      });
    },
    //根据订单查询路由path路径
    findProductUrl(orderNumber) {
      getProductUrl({
        orderNumber: orderNumber
      }).then(res => {
        this.ProductUrl = res.data.productUrl;
        this.markUpdate = res.data.markUpdate;
        this.orderStatus = res.data.orderStatus;
      });
    },
    //处理订单更新
    markUpdateFun() {
      this.markForm.orderNumber = this.orderNumber;
      markUpdate(this.markForm).then(res => {
        if (res.code == 200) {
          this.$message({
            message: res.message,
            type: "success"
          });
          this.$router.replace({ path: this.ProductUrl });
        } else {
          this.$message({
            message: res.message,
            type: "error"
          });
        }
      });
    }
  }
};
</script>

<style scoped type="less">
.first {
  line-height: 35px;
  text-align: left;
  overflow: hidden;
}
h1 {
  float: left;
}
span {
  margin-right: 10px;
}
</style>
